<?php
function set_cookie($name,$value,$seconds){
    return setcookie(encode($name), encode($value), time()+$seconds, "/", null, false, true);
}
function unset_cookie($name){
    return set_cookie(encode($name), null, time()-3600);
}
function get_cookie($name){
    return decode($_COOKIE[encode($name)]);
}

function encode($string) {
    $key = sha1(sha1_key);
    $strLen = strlen($string);
    $keyLen = strlen($key);
    for ($i = 0; $i < $strLen; $i++) {
        $ordStr = ord(substr($string,$i,1));
        if ($j == $keyLen) { $j = 0; }
        $ordKey = ord(substr($key,$j,1));
        $j++;
        $hash .= strrev(base_convert(dechex($ordStr + $ordKey),16,36));
    }
    return $hash;
}
function decode($string) {
    $key = sha1(sha1_key);
    $strLen = strlen($string);
    $keyLen = strlen($key);
    for ($i = 0; $i < $strLen; $i+=2) {
        $ordStr = hexdec(base_convert(strrev(substr($string,$i,2)),36,16));
        if ($j == $keyLen) { $j = 0; }
        $ordKey = ord(substr($key,$j,1));
        $j++;
        $hash .= chr($ordStr - $ordKey);
    }
    return $hash;
}
?>